var MOD_CLX= {
  impver:1
};


MOD_CLX.onchangeclaimtxt=function(cl) {
  var obj=html_flexarea_selected();
  SetFeatureDesc(cl,1,obj.value);
  obj.rows=countLines(obj.value,60);
  obj.value=GetFeatureDesc(cl,1);
  
  SetClaimVerbatim(cl,GetFeatureDesc(cl,1));

}

MOD_CLX.showtxtclaim=function(cl) {
  var tf_iter= new claim_features_iterator(cl);
  var html="";
  if(!tf_iter.end()) { 
    html+="<TR><TD></TD>";  
    html+="<TD valign=bottom>";
    if(tf_iter.length()>1) { // lock modifs on text 
      html+=html_flexarea(GetClaimDescription(cl),""," readonly class='ROTXT' ",70);
    } else {
      html+=html_flexarea(GetClaimDescription(cl),"MOD_CLX.onchangeclaimtxt("+cl+")"," class='RWTXT' ",70);
    }
    html+="<BR></TD></TR>";
  }
  return html;
}


MOD_CLX.onchangeclaimtxtdep=function(cl,dep) {
  SetClaimDep(cl,dep);
  propagate_categories(cl);
  var pcl_iter=new PageClaim_Iterator("cltext");  
  while(!pcl_iter.end()) {
    var pcl=pcl_iter.getValue();
    document.getElementById('clcat'+pcl).className=ClaimTypeStyle(pcl);
    pcl_iter.next();
  }
  document.getElementById('cldep'+cl).value=GetClaimDep(cl);
  CORRUPTEDDOS=1;
  //edit_claimsetview();
}

MOD_CLX._onchangeclaimeq=function(pcl,eq) {
  // Updated to taint
  if(eq) {
    if(GetClaimEq(eq)) {
      if(confirm("Claim "+eq+" is already equivalent to "+GetClaimEq(eq)+". Use this ?")) {
	eq=GetClaimEq(eq);  
      } else {
	return;
      }
    }
    var eq_iter=  Eq_claim_iterator(pcl);
    if(!eq_iter.end()) {
      if(confirm("Other claim(s) are equivalent to "+pcl+". Fix it ?")) {
	while(!eq_iter.end()) {
	  eq_iter.setEq(eq);
	  eq_iter.next();
	}
      } else {
	return ;
      }
    }
  }

  new_Taint(pcl);
  changeEq(pcl,eq);
  var cl_iter= new claim_iterator(pcl);
  while(!cl_iter.end()) {
    var cl=cl_iter.getValue();
    if(IsClaimSearched(cl)) {
      updatefromdocs(cl,GetClaimDep(cl));
    } else {
      updatemanual(cl);
    }
    cl_iter.next();
  }
}

MOD_CLX.onchangeclaimtxteq=function(cl,eq) {
  MOD_CLX._onchangeclaimeq(cl,eq);
  edit_claimsetview();
}


MOD_CLX.txtclimport=function(cl,icl,iver) {
  //alert("import "+iver+"/"+icl+" into "+cl+ " "+MOD_CST.impver);
  claim_import(cl,icl,iver,GetDossierLang());
  edit_claimsetview();
}

MOD_CLX.reparse=function(cl){
  MOD_CLX.onchangeclaimtxtdep(cl,claim_parse(cl,GetClaimDescription(cl)));
}

MOD_CLX.clickonclaim=function(cl) {
  SetFilter("List",cl);
  InitPageClaimIterator(); // not very clean
  edit_features();
}   

MOD_CLX.printhook=function() {
  var html="<TABLE class='LISTTXTCL'>";
  var cl_iter =  new filteredclaims_iterator();
  while(!cl_iter.end()) {
    // alert(cl_iter.getValue());
    html+="<TR><TD VALIGN=top class='LISTTXTCL'>"+cl_iter.getValue();
    html+=". </TD><TD VALIGN=top class='LISTTXTCL'>"+cl_iter.getText()+"<BR>&nbsp</TD></TR>";
    cl_iter.next();
  }
  html+="</TABLE>";
  return html;
}

//
// public
// 


function showtxtallclaims(){
  var html="<TABLE border=1>";
  var NVERS    = GetClaimSetVersion();

  ACT_MOD=MOD_CLX;
  CURRENTVIEW="textview";

  if(NVERS>1) {
    MOD_CST.impver   =html_selected_iter("impver"  ,MOD_CST.impver);   
  }   

  var pcl_iter=new PageClaim_Iterator("cltext");  
  while(!pcl_iter.end()) {
    var cl=pcl_iter.getValue();
    var clclass=ClaimTypeStyle(cl); 

    html+="<TR><TD><input type=button id='clcat"+cl+"' value='Claim "+cl+"' class='"+clclass+"'";
    html+=" onclick='MOD_CLX.clickonclaim("+cl+");'>";
    html+="</TD><TD><TABLE border=0 width=100%><TR>";
    html+="<TH align=left >";
    html+=whatis_D()+" <input type=text class='DEPEQ' id='cldep"+cl+"' value='"+GetClaimDep(cl);
    html+="' id='DEP"+cl+"' onchange='MOD_CLX.onchangeclaimtxtdep("+cl+",this.value)'> ";	
    
    html+=whatis_E()+" <input type=text class='DEPEQ' value='"+GetClaimEq(cl)+"' ";
    html+="onChange='MOD_CLX.onchangeclaimtxteq("+cl+",this.value);'> ";

    if(NVERS>1) {
      html+=whatis_IMP(GetClaimImport(cl))+" <input type=text size=3 value='"+ GetClaimImport(cl)+"'";
      html+=" onChange='MOD_CLX.txtclimport("+cl+",this.value"+",MOD_CST.impver);'>";
    }
    
    if(GetGroupsLength()>1) {
      html+=whatis_G(GetClaimGroup(cl))+" <input type=text size=1 value='"+ GetClaimGroup(cl)+"'";
      html+=" readonly >";
    } 
    html+="</TH>";
    html+="<TD align=center width=400 class='CLHEADER'>Claim Description</TD>";
    html+="<TD width=80 align=right>";
    if(GetFeaturesLength(cl)>1) {
      html+=html_img(lock_img);
    }
    html+=" "+html_img(parse_img,"","onclick=MOD_CLX.reparse("+cl+");")+" ";
    html+="</TD></TR></TABLE></TD>";
    html+="</TR>";
    html+=MOD_CLX.showtxtclaim(cl);     
    
    pcl_iter.next();
  }
  
  html+="</TABLE>";
  return html;
}
